{include file="header.htm" /}
<body class="bodystyle" style="overflow-y: scroll; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    {include file="bar.htm" /}
    <div class="flexigrid flexigrid-xin">
        <div class="mDiv pt0">
            <div class="ftitle">
                <div class="fbutton">
                    <a href="{:weapp_url('PointsShop/PointsShop/add')}">
                        <div class="add">
                            <span><i class="layui-icon layui-icon-addition"></i>添加积分商品</span>
                        </div>
                    </a>
                </div>
            </div>
        </div>

        <div class="header-bar mb20">
            <div class="more">
                <div class="search">
                    <div class="content">
                        <form action="{:weapp_url('PointsShop/PointsShop/index')}" method="get" id="goodsForm" style="display: unset;">
                            {$searchform.hidden|default=''}
                            <div class="ey-form-item">
                                <label class="users-form-item-label">商品名称：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="sDiv2">
                                                <input type="text" size="50" name="title" id="title" value="{$title}" class="qsbox" style="width: 170px;" placeholder="请输入商品名称...">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="ey-form-item">
                                <label class="users-form-item-label">商品状态：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="">
                                                <select name="goods_status" id="goods_status">
                                                    <option value="0" {eq name="$goods_status" value="0"} selected="true" {/eq}>全部</option>
                                                    <option value="1" {eq name="$goods_status" value="1"} selected="true" {/eq}>已上架</option>
                                                    <option value="2" {eq name="$goods_status" value="2"} selected="true" {/eq}>已下架</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="ey-form-item">
                                <label class="users-form-item-label">创建时间：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="sDiv2">
                                                <input type="text" name="startTime" id="startTime" value="{$startTime}" autocomplete="off" value="" class="qsbox" placeholder="起始日期" lay-key="1">
                                            </div>
                                            &nbsp;至&nbsp;
                                            <div class="sDiv2">
                                                <input type="text" name="stopTime" id="stopTime" value="{$stopTime}" autocomplete="off" value="" class="qsbox" placeholder="结束日期" lay-key="2">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <div class="ey-form-item" style="margin-left: 20px;">
                            <div class="users-form-item-content">
                                <span class="bt-xin" onclick="goodsSearch();">查询</span>
                                <span class="bt-xin-no" onclick="unifiedJump(this);" data-url="{:weapp_url('PointsShop/PointsShop/index')}">重置</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 商品列表及分页加载 -->
        <div id="goodsList">{include file="goods_list.htm" /}</div>
    </div>
</div>
<script type="text/javascript">
    layui.use('laydate', function() {
        // 执行一个laydate实例
        var laydate = layui.laydate;
        laydate.render({ elem: '#startTime' });
        laydate.render({ elem: '#stopTime' });
    });

    function goodsSearch() {
        layer_loading('正在处理');
        $('#goodsForm').submit();
        // $('#goodsList').hide();
        // layer_loading('正在处理');
        // var title = $('#title').val();
        // var goods_status = $('#goods_status').val();
        // $.ajax({
        //     url : "{:weapp_url('PointsShop/PointsShop/goodsSearch')}",
        //     data: {title: title, goods_status: goods_status, _ajax: 1},
        //     type: 'post',
        //     dataType: 'json',
        //     success: function(res) {
        //         layer.closeAll();
        //         if (1 === parseInt(res.code)) {
        //             $('#goodsList').show().empty().html(res.data.goodsList);
        //         } else {
        //             $('#goodsList').show();
        //             layer.alert(res.msg, {title: false, closeBtn: false});
        //         }
        //     },
        //     error: function(e) {
        //         layer.closeAll();
        //         $('#goodsList').show();
        //         layer.alert(e.responseText, {title: false, closeBtn: false});
        //     }
        // });
    }

    function goodsStatus(goods_id, goods_status) {
        var title = 2 === parseInt(goods_status) ? '下架' : '上架';
        layer.confirm('确认' + title + '此商品？', {
            move: false,
            closeBtn: 3,
            title: '提示',
            btnAlign: 'r',
            shade: layer_shade,
            btn: ['确定', '取消'],
            area: ['480px', '190px'],
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            layer_loading('正在处理');
            $.ajax({
                url : "{:weapp_url('PointsShop/PointsShop/goodsStatus')}",
                data: {goods_id: goods_id, goods_status: goods_status, _ajax: 1},
                type: 'post',
                dataType: 'json',
                success: function(res) {
                    layer.closeAll();
                    if (1 === parseInt(res.code)) {
                        layer.msg(res.msg, {time: 1500});
                        $('#goodsList').show().empty().html(res.data.goodsList);
                    } else {
                        layer.alert(res.msg, {title: false, closeBtn: false});
                    }
                },
                error: function(e) {
                    layer.closeAll();
                    layer.alert(e.responseText, {title: false, closeBtn: false});
                }
            });
        }, function(index) {
            layer.close(index);
        });
    }

    function goodsDelete(goods_id) {
        layer.confirm('确认删除此商品？', {
            move: false,
            closeBtn: 3,
            title: '提示',
            btnAlign: 'r',
            shade: layer_shade,
            btn: ['确定', '取消'],
            area: ['480px', '190px'],
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            layer_loading('正在处理');
            $.ajax({
                url : "{:weapp_url('PointsShop/PointsShop/goodsDelete')}",
                data: {goods_id: goods_id, _ajax: 1},
                type: 'post',
                dataType: 'json',
                success: function(res) {
                    layer.closeAll();
                    if (1 === parseInt(res.code)) {
                        layer.msg(res.msg, {time: 1500});
                        $('#goodsList').show().empty().html(res.data.goodsList);
                    } else {
                        layer.alert(res.msg, {title: false, closeBtn: false});
                    }
                },
                error: function(e) {
                    layer.closeAll();
                    layer.alert(e.responseText, {title: false, closeBtn: false});
                }
            });
        }, function(index) {
            layer.close(index);
        });
    }
</script>
{include file="footer.htm" /}